package com.molin.threadTest.threadTools.HashtableTest;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.concurrent.ConcurrentHashMap;

public class Demo1 {
    public static void main(String[] args) throws InterruptedException {
        //Hashtable应为是synchionzed悲观锁，所以效率低
        //Hashtable<String,String> hashMap=new Hashtable<>();
        ConcurrentHashMap<String,String> hashMap=new ConcurrentHashMap();
        Thread thread1=new Thread(
                ()->{
                    for (int i = 0; i < 25; i++) {
                        hashMap.put(i+"",i+"");
                    }
                }
        );
        Thread thread2=new Thread(
                ()->{
                    for (int i = 25; i < 51; i++) {
                        hashMap.put(i+"",i+"");
                    }
                }
        );

        thread1.start();

        thread2.start();
        Thread.sleep(1000);
        hashMap.forEach(
                (String s1,String s2)->{
            System.out.println(s1+"---"+s2);
        }
        );
    }
}
